package com.demo.activemq;

import javax.jms.*;

public class CustomerMsgListener implements MessageListener {

    private BusinessHandler businessHandler;

    public CustomerMsgListener(BusinessHandler businessHandler) {
        this.businessHandler = businessHandler;
    }

    @Override
    public void onMessage(Message message) {
        try {
            if (message instanceof TextMessage) {
                businessHandler.handle(((TextMessage) message).getText() );
            }
            if (message instanceof MapMessage) {
                MapMessage mapMessage = (MapMessage) message;
                businessHandler.handle(mapMessage.getString("key01") );
                businessHandler.handle(mapMessage.getString("key02") );
            }
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
